package zgrjb.snbq.teach_platform.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import zgrjb.snbq.teach_platform.component.OSSComponent;
import zgrjb.snbq.teach_platform.dto.req.AddExamRequest;
import zgrjb.snbq.teach_platform.dto.req.AddFileRequest;
import zgrjb.snbq.teach_platform.dto.req.CreateClassRequest;
import zgrjb.snbq.teach_platform.dto.req.FeedbackAdviceRequest;
import zgrjb.snbq.teach_platform.service.*;
import zgrjb.snbq.teach_platform.util.JsonData;


@RestController
@RequestMapping(value =  "/api/v1/tea")
public class TeacherController {

    @Autowired
    private ClassService classService;

    @Autowired
    private AttendService attendService;

    @Autowired
    private FileService fileService;

    @Autowired
     private OSSComponent ossComponent;

    @Autowired
    private AdviceService adviceService;

    @Autowired
    private ExamService examService;



    /**
     * 老师创建班级
     */
    @GetMapping("create")
    public JsonData create(@RequestBody CreateClassRequest request){
        JsonData jsonData = classService.create(request);
        return jsonData;

    }


    /**
     * 老师删除班级
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public JsonData delete(@PathVariable("id") Long id){
        JsonData jsonData = classService.delete(id);
        return jsonData;
    }

    /**
     * 老师获取班级列表
     * @return
     */
    @GetMapping("list_class")
    public JsonData getList() {
        return classService.getList();
    }




    /**
     * 教师同意入班申请
     */
    @GetMapping("allow")
    public JsonData allow(@RequestParam(value =  "stuId")Long stuId, @RequestParam(value =  "classId")Long classId){
        JsonData jsonData = attendService.allow(stuId, classId);
        return jsonData;
    }

    /**
     * 教师获取班级的成员组成
     * allow 0 未入班 1 已入班
     * @param allow
     * @param id
     * @return
     */
    @GetMapping("attend/{classId}")
    public JsonData getAttendees(@RequestParam(value = "allow")Integer allow,@PathVariable("classId") Long id){
        JsonData jsonData = attendService.getAttendees(allow, id);
        return jsonData;
    }


    /**
     * 统一上传文件接口
     * @param file
     * @return
     */
    @PostMapping("upload_file")
    public JsonData uploadFile(@RequestPart("file") MultipartFile file){
        JsonData jsonData = ossComponent.uploadFile(file);
        return jsonData;
    }

    /**
     * 添加课堂文件
     */
    @PostMapping("add_file")
    public JsonData addAddFile(@RequestBody AddFileRequest request){
        JsonData jsonData = fileService.addAddFile(request);
        return jsonData;
    }

    /**
     * 获取班级文件列表
     * 包括发布和未发布的文件
     * @param classId
     * @return
     */
    @GetMapping("list_file")
    public JsonData listFile(@RequestParam(value = "classId") Long classId){
        JsonData jsonData = fileService.listAll(classId);
        return jsonData;
    }


    /**
     * 发布文件，使学生可以看见
     * @param fileId
     * @return
     */
    @PutMapping("publish_file")
    public JsonData publishFile(@RequestParam(value = "fileId") Long fileId){
        JsonData jsonData = fileService.publishFile(fileId);
        return jsonData;
    }


    /**
     * 删除文件
     * @param fileId
     * @return
     */
    @PutMapping("del_file")
    public JsonData delFile(@RequestParam(value = "fileId") Long fileId){
        JsonData jsonData = fileService.delFile(fileId);
        return jsonData;
    }

    @GetMapping("list_advice")
    public JsonData getListAdvice(@RequestParam("class_id")Long classId){
        JsonData jsonData = adviceService.listAll(classId);
        return jsonData;
    }

    @PostMapping("feedback_advice")
    public JsonData feedbackAdvice(@RequestBody FeedbackAdviceRequest request){
        JsonData jsonData = adviceService.feedbackAdvice(request);
        return jsonData;
    }

    @PostMapping("add_exam")
    public JsonData addExam(@RequestBody AddExamRequest request){
        JsonData jsonData = examService.add(request);
        return jsonData;
    }

    @GetMapping("list_exam")
    public JsonData listExam(@RequestParam("class_id")Long classId){
        JsonData jsonData = examService.list(classId);
        return jsonData;
    }


}
